import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'order/good_status.dart';
import '../utils/dio_util.dart';
import '../widget/my_dialog.dart';
import '../widget/error_page.dart';
import '../widget/empty_page.dart';
class OrderPage extends StatefulWidget {
  OrderPage({Key key}) : super(key: key);

  _OrderPageState createState() => _OrderPageState();
}

class _OrderPageState extends State<OrderPage> {
  List _orderList = [];

  Future<Map<String,dynamic>> getOrderList() async{
    String api='/api/mall/order/pageList.service';
    DioUtil dio=DioUtil();
    Map param={
      'pageIndex':1,
      'pageSize':10,
      'orderStatus':'待发货'
    };
   return await dio.get(api,data:param);
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        leading: BackButton(
          color: Colors.white,
        ),
        backgroundColor: Colors.red,
        title: Text(
          "我的订单",
          style: TextStyle(
              color: Colors.white,
              fontSize: 30.sp,
              fontWeight: FontWeight.bold),
        ),
        centerTitle: true,
      ),
      body:
      FutureBuilder<Map<String,dynamic>>(
        future: getOrderList(),
        builder: (context, AsyncSnapshot snapshot) {
          print(snapshot.data);
          switch (snapshot.connectionState) {
            case ConnectionState.none:
            case ConnectionState.waiting:
              return CustomLoaddingDialog(
                  height: 150.0, width: 150, title: '努力加载中');
              break;
            case ConnectionState.done: // -------- 完成态
              if (snapshot.hasError) { // 异常
                print(snapshot.error);
                return ErrorPage(error:snapshot.error.toString());
              }else{// 正常
                if (snapshot.data['code'] == 200) {
                  var result = snapshot.data['result'];
                  if(result.isEmpty){
                    return EmptyPage();
                  }
                  return RefreshIndicator(
                      displacement: 20,
                      strokeWidth: 4,
                      color: Colors.red,
                      onRefresh: getOrderList,
                      child: CustomScrollView(
                        physics:BouncingScrollPhysics(),
                        slivers: [
                          SliverToBoxAdapter(
                            child: Container(
                              alignment: Alignment.topCenter,
                              padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 25.w),
                              height: 200.w,
                              decoration: BoxDecoration(color: Colors.red),
                              child: Container(
                                height: 150.w,
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    Column(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Text(
                                          '订单信息',
                                          style: TextStyle(color: Colors.white, fontSize: 45.sp),
                                        ),
                                        SizedBox(
                                          height: 20.w,
                                        ),
                                        Text(
                                          '消费订单: 0 总消费：￥0',
                                          style: TextStyle(color: Colors.white, fontSize: 25.sp),
                                        )
                                      ],
                                    ),
                                    Icon(
                                      Icons.star_border,
                                      size: 100.sp,
                                      color: Colors.white,
                                    )
                                  ],
                                ),
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: GoodStatus(),
                          ),

                        ],
                      ));
                }else if(snapshot.data['code']!=200){
                  return ErrorPage(error:snapshot.data['msg']);
                }
              }
              break;
            default:
              break;
          }
        },
      )


      ,
    );
  }
}
